@elice/material-quiz 1.221217.0 → 1.221222.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,28 +18,24 @@ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
18
18
  var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
19
19
  var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
20
20
 
21
- const OPTION_CONTENT_WIDTH = 205;
22
- const OPTION_GROUP_WIDTH = 180;
23
- const MIN_OPTION_INFO_COUNT = 2;
24
21
  const MAX_OPTION_INFO_COUNT = 20;
25
- const StyledSortableList = styled__default["default"].ul.withConfig({
22
+ const StyledSortableList = styled__default["default"].div.withConfig({
26
23
  componentId: "sc-14yoda7-0"
27
24
  })(["margin:1rem 0;padding:0;"]);
28
- const StyledSortableListItemWrapper = styled__default["default"].li.withConfig({
25
+ const StyledSortableListItemWrapper = styled__default["default"].div.withConfig({
29
26
  componentId: "sc-14yoda7-1"
30
27
  })(["display:flex;flex-direction:column;width:100%;&:not(:last-child){margin-bottom:0.5rem;}"]);
31
28
  const StyledOptionTitle = styled__default["default"].div.withConfig({
32
29
  componentId: "sc-14yoda7-2"
33
- })(["display:flex;width:calc(100% - 2rem);"]); //
30
+ })(["display:flex;width:calc(100% - 2rem - 1.5rem);"]); //
34
31
  //
35
32
  //
36
33
 
37
- const OptionGroupAnswerList = () => {
34
+ const OptionGroupAnswerInfo = () => {
38
35
  const intl = reactIntl.useIntl();
39
36
  const {
40
- formState,
41
- watch,
42
- setValue
37
+ setValue,
38
+ watch
43
39
  } = reactHookForm.useFormContext();
44
40
  const {
45
41
  append: appendOptionInfoFieldItem,
@@ -49,10 +45,9 @@ const OptionGroupAnswerList = () => {
49
45
  keyName: 'id',
50
46
  shouldUnregister: true
51
47
  });
52
- const optionInfoFields = watch('options');
48
+ const watchedOptions = watch('options');
53
49
  const watchedAnswerInfo = watch('answerInfo');
54
- const isMinimumOptions = (optionInfoFields === null || optionInfoFields === void 0 ? void 0 : optionInfoFields.length) <= MIN_OPTION_INFO_COUNT;
55
- const isMaximumOptions = (optionInfoFields === null || optionInfoFields === void 0 ? void 0 : optionInfoFields.length) >= MAX_OPTION_INFO_COUNT;
50
+ const isMaximumOptions = (watchedOptions === null || watchedOptions === void 0 ? void 0 : watchedOptions.length) >= MAX_OPTION_INFO_COUNT;
56
51
  /**
57
52
  *
58
53
  */
@@ -69,97 +64,12 @@ const OptionGroupAnswerList = () => {
69
64
  const recalculationAnswerList = cloneAnswerList.map(answers => answers.map(answer => answer > index ? answer - 1 : answer));
70
65
  removeOptionInfoFieldItem(index);
71
66
  setValue('answerInfo', recalculationAnswerList);
72
- }; //
73
- //
74
- //
75
-
76
-
77
- if (!checkTwoDimensionArray.checkTwoDimensionArray(watchedAnswerInfo)) {
78
- return null;
79
- }
80
-
81
- return React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement(StyledSortableList, null, optionInfoFields === null || optionInfoFields === void 0 ? void 0 : optionInfoFields.map((option, index) => {
82
- var _a, _b, _c, _d;
83
-
84
- const errorMessage = (_d = (_c = (_b = (_a = formState.errors) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b[index]) === null || _c === void 0 ? void 0 : _c.title) === null || _d === void 0 ? void 0 : _d.message;
85
- return React__default["default"].createElement(StyledSortableListItemWrapper, {
86
- key: option.id
87
- }, React__default["default"].createElement(blocks.Flex, {
88
- align: "center",
89
- width: "100%"
90
- }, React__default["default"].createElement(OptionGroupAnswerListItem, {
91
- optionId: index
92
- }), React__default["default"].createElement(blocks.Hspace, {
93
- width: 0.5
94
- }), React__default["default"].createElement(blocks.Tooltip, {
95
- title: isMinimumOptions ? intl.formatMessage({
96
- id: 'answer.option.tooltip.minDisabled'
97
- }) : undefined,
98
- placement: "top"
99
- }, React__default["default"].createElement("span", null, React__default["default"].createElement(blocks.IconButton, {
100
- transparent: true,
101
- icon: icons.eilMathsignMultiplyBasic,
102
- role: "gray6",
103
- size: "micro",
104
- border: false,
105
- disabled: isMinimumOptions,
106
- onClick: () => handleRemoveItem(index)
107
- })))), errorMessage ? React__default["default"].createElement(blocks.Text, {
108
- size: "small",
109
- role: "danger"
110
- }, errorMessage) : null);
111
- })), React__default["default"].createElement(blocks.Tooltip, {
112
- title: isMaximumOptions ? intl.formatMessage({
113
- id: 'answer.option.tooltip.maxDisabled'
114
- }) : undefined,
115
- placement: "top"
116
- }, React__default["default"].createElement("span", null, React__default["default"].createElement(blocks.Button, {
117
- borderDashed: true,
118
- block: true,
119
- transparent: true,
120
- disabled: isMaximumOptions,
121
- icon: React__default["default"].createElement(blocks.Icon, {
122
- icon: icons.eilMathsignAddBasic
123
- }),
124
- onClick: () => appendOptionInfoFieldItem({
125
- id: randomId.createRandomId(),
126
- title: '',
127
- content: ''
128
- })
129
- }, intl.formatMessage({
130
- id: 'answer.option.addButton'
131
- })))), React__default["default"].createElement(blocks.Vspace, {
132
- height: 0.5
133
- }), React__default["default"].createElement(blocks.StatusText, {
134
- role: "description"
135
- }, intl.formatMessage({
136
- id: 'answer.option.file.description.imageSize'
137
- })), React__default["default"].createElement(blocks.StatusText, {
138
- role: "description"
139
- }, intl.formatMessage({
140
- id: 'answer.option.file.description.fileSize'
141
- })), React__default["default"].createElement(blocks.StatusText, {
142
- role: "description"
143
- }, intl.formatMessage({
144
- id: 'answer.option.file.description.extension'
145
- })));
146
- }; //
147
- //
148
- //
149
-
150
-
151
- const OptionGroupAnswerInfo = () => {
152
- const intl = reactIntl.useIntl();
153
- const {
154
- setValue,
155
- watch
156
- } = reactHookForm.useFormContext();
157
- const watchedOptions = watch('options');
158
- const watchedAnswerInfo = watch('answerInfo');
67
+ };
159
68
  /**
160
69
  *
161
70
  */
162
71
 
72
+
163
73
  const onSortEnd = ({
164
74
  oldIndex,
165
75
  newIndex
@@ -175,38 +85,108 @@ const OptionGroupAnswerInfo = () => {
175
85
  setValue('options', reactSortableHoc.arrayMove(watchedOptions, oldIndex, newIndex), {
176
86
  shouldDirty: true
177
87
  });
88
+ };
89
+ /**
90
+ *
91
+ */
92
+
93
+
94
+ const renderAnswerTitle = () => {
95
+ return React__default["default"].createElement(StyledOptionTitle, null, React__default["default"].createElement(blocks.Flex, {
96
+ width: "33.3%",
97
+ auto: true
98
+ }, React__default["default"].createElement(blocks.Text, {
99
+ size: "small",
100
+ bold: true
101
+ }, intl.formatMessage({
102
+ id: 'answer.option.title.text'
103
+ }))), React__default["default"].createElement(blocks.Flex, {
104
+ width: "33.3%"
105
+ }, React__default["default"].createElement(blocks.Text, {
106
+ size: "small",
107
+ bold: true
108
+ }, intl.formatMessage({
109
+ id: 'answer.option.title.file'
110
+ }))), React__default["default"].createElement(blocks.Flex, {
111
+ width: "calc(33.3% - 1.5rem)"
112
+ }, React__default["default"].createElement(blocks.Text, {
113
+ size: "small",
114
+ bold: true
115
+ }, intl.formatMessage({
116
+ id: 'answer.option.title.group'
117
+ }))));
118
+ };
119
+ /**
120
+ *
121
+ */
122
+
123
+
124
+ const renderAnswerOptionList = () => {
125
+ return React__default["default"].createElement(blocks.SortableListGroup, {
126
+ onSortEnd: onSortEnd,
127
+ useDragHandle: true
128
+ }, React__default["default"].createElement(StyledSortableList, null, watchedOptions === null || watchedOptions === void 0 ? void 0 : watchedOptions.map((option, index) => React__default["default"].createElement(StyledSortableListItemWrapper, {
129
+ key: option.id
130
+ }, React__default["default"].createElement(OptionGroupAnswerListItem, {
131
+ optionId: index,
132
+ onRemoveItem: () => handleRemoveItem(index)
133
+ })))));
134
+ };
135
+ /**
136
+ *
137
+ */
138
+
139
+
140
+ const renderAnswerOptionAddButton = () => {
141
+ return React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement(blocks.Tooltip, {
142
+ title: isMaximumOptions ? intl.formatMessage({
143
+ id: 'answer.option.tooltip.maxDisabled'
144
+ }) : undefined,
145
+ placement: "top"
146
+ }, React__default["default"].createElement("span", null, React__default["default"].createElement(blocks.Button, {
147
+ borderDashed: true,
148
+ block: true,
149
+ transparent: true,
150
+ disabled: isMaximumOptions,
151
+ icon: React__default["default"].createElement(blocks.Icon, {
152
+ icon: icons.eilMathsignAddBasic
153
+ }),
154
+ onClick: () => appendOptionInfoFieldItem({
155
+ id: randomId.createRandomId(),
156
+ title: '',
157
+ content: ''
158
+ })
159
+ }, intl.formatMessage({
160
+ id: 'answer.option.addButton'
161
+ })))), React__default["default"].createElement(blocks.Vspace, {
162
+ height: 0.5
163
+ }), React__default["default"].createElement(blocks.Flex, {
164
+ column: true
165
+ }, React__default["default"].createElement(blocks.StatusText, {
166
+ role: "description"
167
+ }, intl.formatMessage({
168
+ id: 'answer.option.file.description.imageSize'
169
+ })), React__default["default"].createElement(blocks.StatusText, {
170
+ role: "description"
171
+ }, intl.formatMessage({
172
+ id: 'answer.option.file.description.fileSize'
173
+ })), React__default["default"].createElement(blocks.StatusText, {
174
+ role: "description"
175
+ }, intl.formatMessage({
176
+ id: 'answer.option.file.description.extension'
177
+ }))));
178
178
  }; //
179
179
  //
180
180
  //
181
181
 
182
182
 
183
+ if (!checkTwoDimensionArray.checkTwoDimensionArray(watchedAnswerInfo)) {
184
+ return null;
185
+ }
186
+
183
187
  return React__default["default"].createElement(blocks.Flex, {
184
188
  column: true
185
- }, React__default["default"].createElement(StyledOptionTitle, null, React__default["default"].createElement(blocks.Flex, {
186
- auto: true
187
- }, React__default["default"].createElement(blocks.Text, {
188
- size: "small",
189
- bold: true
190
- }, intl.formatMessage({
191
- id: 'answer.option.title.text'
192
- }))), React__default["default"].createElement(blocks.Flex, {
193
- width: `${OPTION_CONTENT_WIDTH}px`
194
- }, React__default["default"].createElement(blocks.Text, {
195
- size: "small",
196
- bold: true
197
- }, intl.formatMessage({
198
- id: 'answer.option.title.file'
199
- }))), React__default["default"].createElement(blocks.Flex, {
200
- width: `${OPTION_GROUP_WIDTH}px`
201
- }, React__default["default"].createElement(blocks.Text, {
202
- size: "small",
203
- bold: true
204
- }, intl.formatMessage({
205
- id: 'answer.option.title.group'
206
- })))), React__default["default"].createElement(blocks.SortableListGroup, {
207
- onSortEnd: onSortEnd,
208
- useDragHandle: true
209
- }, React__default["default"].createElement(OptionGroupAnswerList, null)));
189
+ }, renderAnswerTitle(), renderAnswerOptionList(), renderAnswerOptionAddButton());
210
190
  };
211
191
 
212
192
  module.exports = OptionGroupAnswerInfo;
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  interface OptionGroupAnswerListItemProps {
3
3
  optionId: number;
4
+ onRemoveItem: () => void;
4
5
  }
5
6
  declare const OptionGroupAnswerListItem: React.FC<OptionGroupAnswerListItemProps>;
6
7
  export default OptionGroupAnswerListItem;
@@ -19,54 +19,59 @@ var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep);
19
19
  var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
20
20
 
21
21
  const SHEET_Z_INDEX = 982;
22
- const OPTION_CONTENT_WIDTH = 205;
23
- const OPTION_GROUP_WIDTH = 180;
24
22
  const DEFAULT_OPTION_VALUE = -1;
23
+ const MIN_OPTION_INFO_COUNT = 2;
25
24
  const FILE_LABEL = 'file-label';
26
25
  const FILE_ACCEPT = '.mp3, .mp4, .mov, .png, .jpg, .svg, .gif';
27
26
  const MAX_FILE_SIZE = 3 * 1024 * 1024;
28
27
  const StyledSortableListItem = styled__default["default"](blocks.SortableListItem).withConfig({
29
28
  componentId: "sc-18q96lt-0"
30
- })(["display:flex;overflow:hidden;flex:1;z-index:", ";height:3.5rem;padding:0 0 0 1rem;border-radius:4px;border:1px solid ", ";background:", ";box-shadow:none;"], SHEET_Z_INDEX + 1, designTokens.base.color.gray3, designTokens.base.color.white);
31
- const StyledSortableListItemOption = styled__default["default"].div.withConfig({
29
+ })(["display:flex;flex:1;z-index:", ";padding:0;background:transparent;box-shadow:none;"], SHEET_Z_INDEX + 1);
30
+ const StyledSortableListItemOptionWrapper = styled__default["default"].div.withConfig({
32
31
  componentId: "sc-18q96lt-1"
33
- })(["height:100%;&:not(:last-child){border-right:1px solid ", ";}"], designTokens.base.color.gray3);
34
- const StyledQuizOptionContent = styled__default["default"].div.withConfig({
32
+ })(["display:flex;align-items:center;overflow:hidden;width:100%;height:100%;border:1px solid ", ";border-radius:4px;background:", ";"], designTokens.base.color.gray3, designTokens.base.color.white);
33
+ const StyledSortableListItemOption = styled__default["default"].div.withConfig({
35
34
  componentId: "sc-18q96lt-2"
36
- })(["display:flex;align-items:center;width:", "px;height:100%;padding:0 1rem;"], OPTION_CONTENT_WIDTH);
37
- const StyledQuizOptionContentLabel = styled__default["default"].label.withConfig({
35
+ })(["height:3.5rem;&:not(:last-child){border-right:1px solid ", ";}"], designTokens.base.color.gray3);
36
+ const StyledQuizOptionContent = styled__default["default"].div.withConfig({
38
37
  componentId: "sc-18q96lt-3"
39
- })(["display:flex;align-items:center;width:", "px;height:100%;padding:0 1rem;cursor:pointer;"], OPTION_CONTENT_WIDTH);
40
- const StyledQuizOptionTextInput = styled__default["default"](blocks.Input).withConfig({
38
+ })(["display:flex;align-items:center;width:100%;height:100%;padding:0 1rem;"]);
39
+ const StyledQuizOptionContentLabel = styled__default["default"].label.withConfig({
41
40
  componentId: "sc-18q96lt-4"
41
+ })(["display:flex;align-items:center;width:100%;height:100%;padding:0 1rem;cursor:pointer;"]);
42
+ const StyledQuizOptionTextInput = styled__default["default"](blocks.Input).withConfig({
43
+ componentId: "sc-18q96lt-5"
42
44
  })(["& > div{border:0;}"]);
43
45
  const StyledQuizOptionContentInput = styled__default["default"].input.withConfig({
44
- componentId: "sc-18q96lt-5"
46
+ componentId: "sc-18q96lt-6"
45
47
  })(["display:none;"]);
46
48
  const StyledDropdown = styled__default["default"](blocks.Dropdown).withConfig({
47
- componentId: "sc-18q96lt-6"
48
- })(["border:0;&.eb-dropdown__inner{width:", "px;height:3.5rem;}"], OPTION_GROUP_WIDTH); //
49
+ componentId: "sc-18q96lt-7"
50
+ })(["border:0;&.eb-dropdown__inner{width:100%;height:3.5rem;}"]); //
49
51
  //
50
52
  //
51
53
 
52
54
  const OptionGroupAnswerListItem = ({
53
- optionId
55
+ optionId,
56
+ onRemoveItem
54
57
  }) => {
55
- var _a, _b, _c, _d;
58
+ var _a, _b, _c, _d, _e, _f, _g, _h;
56
59
 
57
60
  const intl = reactIntl.useIntl();
58
61
  const {
59
62
  control,
63
+ formState,
60
64
  watch,
61
65
  setValue
62
66
  } = reactHookForm.useFormContext();
63
67
  const watchedOptions = watch('options');
64
68
  const watchedAnswerInfo = watch('answerInfo');
65
69
  const watchedGroupList = watch('groups');
66
- const isReady = materialSharedUtils.useMaterialConfigApiClientUpdate(apiClient.config.init);
70
+ const errorMessage = (_d = (_c = (_b = (_a = formState.errors) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b[optionId]) === null || _c === void 0 ? void 0 : _c.title) === null || _d === void 0 ? void 0 : _d.message;
67
71
  const groupIndex = watchedAnswerInfo.findIndex(answer => answer === null || answer === void 0 ? void 0 : answer.includes(optionId));
68
- const isOptionTitle = (_b = (_a = watchedOptions[optionId]) === null || _a === void 0 ? void 0 : _a.title) === null || _b === void 0 ? void 0 : _b.length;
69
- const isOptionContent = (_d = (_c = watchedOptions[optionId]) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.length;
72
+ const isReady = materialSharedUtils.useMaterialConfigApiClientUpdate(apiClient.config.init);
73
+ const isOptionTitle = (_f = (_e = watchedOptions[optionId]) === null || _e === void 0 ? void 0 : _e.title) === null || _f === void 0 ? void 0 : _f.length;
74
+ const isOptionContent = (_h = (_g = watchedOptions[optionId]) === null || _g === void 0 ? void 0 : _g.content) === null || _h === void 0 ? void 0 : _h.length;
70
75
  /**
71
76
  * File upload function.
72
77
  */
@@ -95,122 +100,204 @@ const OptionGroupAnswerListItem = ({
95
100
  }
96
101
 
97
102
  return contentUrl;
98
- }; //
99
- //
100
- //
103
+ };
104
+ /**
105
+ *
106
+ */
101
107
 
102
108
 
103
- if (!checkTwoDimensionArray.checkTwoDimensionArray(watchedAnswerInfo)) {
104
- return null;
105
- }
109
+ const renderOptionTitleInput = () => {
110
+ return React__default["default"].createElement(StyledSortableListItemOption, {
111
+ style: {
112
+ width: '33.3%'
113
+ }
114
+ }, React__default["default"].createElement(reactHookForm.Controller, {
115
+ control: control,
116
+ name: `options.${optionId}.title`,
117
+ rules: {
118
+ required: {
119
+ value: !isOptionTitle && !isOptionContent,
120
+ message: intl.formatMessage({
121
+ id: 'answer.option.errorMessage'
122
+ })
123
+ }
124
+ },
125
+ render: ({
126
+ field
127
+ }) => React__default["default"].createElement(StyledQuizOptionTextInput, Object.assign({}, field, {
128
+ width: "full",
129
+ onChange: e => {
130
+ field.onChange(e.target.value.replace(' ', ''));
131
+ }
132
+ }))
133
+ }));
134
+ };
135
+ /**
136
+ *
137
+ */
106
138
 
107
- return React__default["default"].createElement(StyledSortableListItem, {
108
- index: optionId
109
- }, React__default["default"].createElement(StyledSortableListItemOption, {
110
- style: {
111
- flex: 1
112
- }
113
- }, React__default["default"].createElement(reactHookForm.Controller, {
114
- control: control,
115
- name: `options.${optionId}.title`,
116
- rules: {
117
- required: {
118
- value: !isOptionTitle && !isOptionContent,
119
- message: intl.formatMessage({
120
- id: 'answer.option.errorMessage'
121
- })
139
+
140
+ const renderOptionContentInput = () => {
141
+ return React__default["default"].createElement(StyledSortableListItemOption, {
142
+ style: {
143
+ width: '33.3%'
144
+ }
145
+ }, React__default["default"].createElement(reactHookForm.Controller, {
146
+ control: control,
147
+ name: `options.${optionId}.content`,
148
+ render: ({
149
+ field
150
+ }) => React__default["default"].createElement(React__default["default"].Fragment, null, field.value ? React__default["default"].createElement(StyledQuizOptionContent, null, React__default["default"].createElement(blocks.Flex, {
151
+ justify: "space-between",
152
+ align: "center",
153
+ width: "100%",
154
+ height: "100%"
155
+ }, React__default["default"].createElement(blocks.Text, {
156
+ ellipsis: true
157
+ }, React__default["default"].createElement("a", {
158
+ href: getContentUrl(field.value),
159
+ target: "_blank",
160
+ rel: "noreferrer"
161
+ }, getContentUrl(field.value))), React__default["default"].createElement(blocks.Flex, {
162
+ align: "center"
163
+ }, React__default["default"].createElement(blocks.Hspace, {
164
+ width: 0.5
165
+ }), React__default["default"].createElement(blocks.IconButton, {
166
+ icon: icons.eilMathsignMultiplyBasic,
167
+ role: "gray6",
168
+ size: "micro",
169
+ border: false,
170
+ transparent: true,
171
+ onClick: () => field.onChange('')
172
+ })))) : React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement(StyledQuizOptionContentLabel, {
173
+ htmlFor: `${FILE_LABEL}_${optionId}`
174
+ }, React__default["default"].createElement(blocks.Text, {
175
+ role: "primary",
176
+ underline: true
177
+ }, intl.formatMessage({
178
+ id: 'answer.option.file.label'
179
+ }))), React__default["default"].createElement(StyledQuizOptionContentInput, Object.assign({}, field, {
180
+ id: `${FILE_LABEL}_${optionId}`,
181
+ type: "file",
182
+ accept: FILE_ACCEPT,
183
+ onChange: async e => {
184
+ var _a, _b;
185
+
186
+ const file = (_b = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b[0];
187
+
188
+ if (!file) {
189
+ return;
190
+ }
191
+
192
+ if (file.size > MAX_FILE_SIZE) {
193
+ return blocks.Notification.error(intl.formatMessage({
194
+ id: 'answer.option.file.errorMessage.maxSize'
195
+ }, {
196
+ size: 3
197
+ }));
198
+ }
199
+
200
+ const contentFileUrl = await uploadContentFile(file);
201
+ field.onChange(`![](${String(contentFileUrl)})`);
202
+ }
203
+ }))))
204
+ }));
205
+ };
206
+ /**
207
+ *
208
+ */
209
+
210
+
211
+ const renderOptionGroupDropdown = () => {
212
+ return React__default["default"].createElement(StyledSortableListItemOption, {
213
+ style: {
214
+ width: '33.3%'
122
215
  }
123
- },
124
- render: ({
125
- field
126
- }) => React__default["default"].createElement(StyledQuizOptionTextInput, Object.assign({}, field, {
127
- width: "full",
216
+ }, React__default["default"].createElement(StyledDropdown, {
217
+ value: groupIndex,
128
218
  onChange: e => {
129
- field.onChange(e.target.value.replace(' ', ''));
219
+ const cloneAnswerList = cloneDeep__default["default"](watchedAnswerInfo);
220
+ const answerList = cloneAnswerList.map(answers => answers.filter(answer => answer !== optionId));
221
+
222
+ if (e === DEFAULT_OPTION_VALUE) {
223
+ return setValue('answerInfo', answerList);
224
+ }
225
+
226
+ if (answerList[e]) {
227
+ answerList[e] = [...answerList[e], optionId];
228
+ } else {
229
+ answerList[e] = [optionId];
230
+ }
231
+
232
+ setValue('answerInfo', answerList);
130
233
  }
131
- }))
132
- })), React__default["default"].createElement(StyledSortableListItemOption, null, React__default["default"].createElement(reactHookForm.Controller, {
133
- control: control,
134
- name: `options.${optionId}.content`,
135
- render: ({
136
- field
137
- }) => React__default["default"].createElement(React__default["default"].Fragment, null, field.value ? React__default["default"].createElement(StyledQuizOptionContent, null, React__default["default"].createElement(blocks.Flex, {
138
- align: "center",
139
- width: "100%",
140
- height: "100%"
141
- }, React__default["default"].createElement(blocks.Text, {
142
- ellipsis: true
143
- }, React__default["default"].createElement("a", {
144
- href: getContentUrl(field.value),
145
- target: "_blank",
146
- rel: "noreferrer"
147
- }, getContentUrl(field.value))), React__default["default"].createElement(blocks.Hspace, {
234
+ }, React__default["default"].createElement("option", {
235
+ value: DEFAULT_OPTION_VALUE
236
+ }, intl.formatMessage({
237
+ id: 'answer.option.default.group'
238
+ })), watchedGroupList.map((group, index) => React__default["default"].createElement("option", {
239
+ key: index,
240
+ value: index
241
+ }, group.group))));
242
+ };
243
+ /**
244
+ *
245
+ */
246
+
247
+
248
+ const renderOptionRemoveButton = () => {
249
+ const isMinimumOptions = (watchedOptions === null || watchedOptions === void 0 ? void 0 : watchedOptions.length) <= MIN_OPTION_INFO_COUNT;
250
+ return React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement(blocks.Hspace, {
148
251
  width: 0.5
149
- }), React__default["default"].createElement("div", null, React__default["default"].createElement(blocks.IconButton, {
252
+ }), React__default["default"].createElement(blocks.Tooltip, {
253
+ title: isMinimumOptions ? intl.formatMessage({
254
+ id: 'answer.option.tooltip.minDisabled'
255
+ }) : undefined,
256
+ placement: "top"
257
+ }, React__default["default"].createElement("span", null, React__default["default"].createElement(blocks.IconButton, {
258
+ transparent: true,
150
259
  icon: icons.eilMathsignMultiplyBasic,
151
260
  role: "gray6",
152
261
  size: "micro",
153
262
  border: false,
154
- transparent: true,
155
- onClick: () => field.onChange('')
156
- })))) : React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement(StyledQuizOptionContentLabel, {
157
- htmlFor: `${FILE_LABEL}_${optionId}`
158
- }, React__default["default"].createElement(blocks.Text, {
159
- role: "primary",
160
- underline: true
161
- }, intl.formatMessage({
162
- id: 'answer.option.file.label'
163
- }))), React__default["default"].createElement(StyledQuizOptionContentInput, Object.assign({}, field, {
164
- id: `${FILE_LABEL}_${optionId}`,
165
- type: "file",
166
- accept: FILE_ACCEPT,
167
- onChange: async e => {
168
- var _a, _b;
169
-
170
- const file = (_b = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.files) === null || _b === void 0 ? void 0 : _b[0];
171
-
172
- if (!file) {
173
- return;
174
- }
263
+ disabled: isMinimumOptions,
264
+ onClick: onRemoveItem
265
+ }))));
266
+ };
267
+ /**
268
+ *
269
+ */
175
270
 
176
- if (file.size > MAX_FILE_SIZE) {
177
- return blocks.Notification.error(intl.formatMessage({
178
- id: 'answer.option.file.errorMessage.maxSize'
179
- }, {
180
- size: 3
181
- }));
182
- }
183
271
 
184
- const contentFileUrl = await uploadContentFile(file);
185
- field.onChange(`![](${String(contentFileUrl)})`);
186
- }
187
- }))))
188
- })), React__default["default"].createElement(StyledSortableListItemOption, null, React__default["default"].createElement(StyledDropdown, {
189
- value: groupIndex,
190
- onChange: e => {
191
- const cloneAnswerList = cloneDeep__default["default"](watchedAnswerInfo);
192
- const answerList = cloneAnswerList.map(answers => answers.filter(answer => answer !== optionId));
193
-
194
- if (e === DEFAULT_OPTION_VALUE) {
195
- return setValue('answerInfo', answerList);
196
- }
272
+ const renderErrorMessage = () => {
273
+ if (!errorMessage) {
274
+ return null;
275
+ }
197
276
 
198
- if (answerList[e]) {
199
- answerList[e] = [...answerList[e], optionId];
200
- } else {
201
- answerList[e] = [optionId];
202
- }
277
+ return React__default["default"].createElement(blocks.Flex, {
278
+ paddingleft: "0.25rem"
279
+ }, React__default["default"].createElement(blocks.Text, {
280
+ size: "small",
281
+ role: "danger"
282
+ }, errorMessage));
283
+ }; //
284
+ //
285
+ //
203
286
 
204
- setValue('answerInfo', answerList);
205
- }
206
- }, React__default["default"].createElement("option", {
207
- value: DEFAULT_OPTION_VALUE
208
- }, intl.formatMessage({
209
- id: 'answer.option.default.group'
210
- })), watchedGroupList.map((group, index) => React__default["default"].createElement("option", {
211
- key: index,
212
- value: index
213
- }, group.group)))));
287
+
288
+ if (!checkTwoDimensionArray.checkTwoDimensionArray(watchedAnswerInfo)) {
289
+ return null;
290
+ }
291
+
292
+ return React__default["default"].createElement(StyledSortableListItem, {
293
+ index: optionId
294
+ }, React__default["default"].createElement(blocks.Flex, {
295
+ justify: "center",
296
+ width: "calc(100% - 1.5rem)",
297
+ column: true
298
+ }, React__default["default"].createElement(blocks.Flex, {
299
+ align: "center"
300
+ }, React__default["default"].createElement(StyledSortableListItemOptionWrapper, null, renderOptionTitleInput(), renderOptionContentInput(), renderOptionGroupDropdown()), renderOptionRemoveButton()), renderErrorMessage()));
214
301
  };
215
302
 
216
303
  module.exports = OptionGroupAnswerListItem;